//充值金额
function chargeOne(id, action, name, price) {
    var admin_path = '/admin';
    var path = admin_path + "/user/user_list";
    $.confirm({
        title: '会员充值',
        content: '<p style=" font-family: "Microsoft YaHei";font-size: 13px;color: #393939;"><b>您正在进行有关<code>报单费用回填</code>操作，属于敏感操作</b><br><br><label><b>回填报单费用</b></label><br><b>姓名：<code>' + name + '</code>   现在费用：<code>' + price + '</code></b><input autofocus type="money" id="money" placeholder="输入增加的回填金额" class="form-control"><br>按锁计算:<input type="radio" checked name="ansuo" value="1">是<input type="radio"  name="ansuo" value="0">否<br></div><p class="text-danger" style="display:none"><b>金额不能小于现在费用</b></p></p>',
        confirm: function () {
            var input = this.$b.find('input#input-name');
            var errorText = this.$b.find('.text-danger');
            var money = $("#money").val();
            var ansuo = $("input[name='ansuo']:checked").val();
            if (isNaN(money) || money == "" || parseFloat(money) < parseFloat(price)) {
                errorText.show();
                return false;
            } else if (money > 200) {
                errorText.html('请输入小于200的数字');
                errorText.show();
                return false;
            } else {
                $.ajax({
                    async: true,
                    url: admin_path + action,
                    type: "post",
                    data: { id: id, money: money, ansuo: ansuo },
                    dataType: 'json',
                    success: function (data) {
                        if (data['success']) {
                            $.alert({
                                title: '提示',
                                content: '修改成功，请确定',
                                confirm: function () {
                                    window.location.replace(path);
                                }
                            });
                        } else {
                            errorText.html(data.error);
                            errorText.show();

                        }
                    }
                });
                return false;
            }
        }
    });
}

function zhuangtai(id, action, zhuangtai, name) {
    var admin_path = '/admin';
    var path = admin_path + "/user/user_list";

    $.confirm({
        title: '会员' + zhuangtai,
        content: '<p style=" font-family: "Microsoft YaHei";font-size: 13px;color: #393939;"><b>您正在对会员<code>' + name + '进行' + zhuangtai + '操作<code>，属于敏感操作</div><p class="text-danger" style="display:none"><b>金额不能小于现在费用</b></p></p>',
        confirm: function () {
            var errorText = this.$b.find('.text-danger');
            $.ajax({
                async: true,
                url: admin_path + action,
                type: "post",
                data: { id: id },
                dataType: 'json',
                success: function (data) {
                    errorText.html(data.error);
                    errorText.show();
                    window.location.replace(path);
                }
            });
        }
    });
}
function editParent(user_id, username) {

    var path = "/admin/script/editParent?user_id=" + user_id;

    $.confirm({
        title: '会员高管独立',
        backgroundDismiss: false,
        content: '<p style=" font-family: "Microsoft YaHei";font-size: 13px;color: #393939;"><b>您正在对会员' + username + '<code>进行高管独立操作<code>，属于敏感操作</div><p class="text-danger" style="display:none"><b>金额不能小于现在费用</b></p></p>',
        confirm: function () {
            $.dialog({
                id: 'editParentDialogId',
                title: '会员' + username + '高管独立',
                backgroundDismiss: false,
                content: "<div id='editParentMsg'><div>正在修改会员父级id...</div></div>",
                width: 600,
                height: 400,
                onClose: function () {
                    window.location.replace('/admin/user/user_list');
                }
            })
            $.ajax({
                async: true,
                url: path,
                type: "get",
                dataType: 'json',
                success: function (data) {
                    $('#editParentMsg').append('<div>会员修改父级id完成</div>');
                    parent_path();
                }
            });
        }
    });
}
function parent_path() {
    $('#editParentMsg').append('<div>正在调整会员及本会员下级用户的团队路径数据...</div>');
    $.ajax({
        url: '/admin/script/retryPath',
        type: 'get',
        async: true,
        success: function (res) {
            $('#editParentMsg').append('<div>调整会员及本会员下级用户的团队路径数据完成</div>');
            next_count();
        }
    });

}
function next_count() {
    $('#editParentMsg').append('<div>正在调整会员及本会员上级用户的下级数量...</div>');

    $.ajax({
        url: '/admin/script/nextCount?type=nextCount',
        type: 'get',
        async: true,
        success: function (res) {
            $('#editParentMsg').append('<div>调整会员及本会员上级用户的下级数量完成</div>');
            next_next_count();

        }
    })


}
function next_next_count() {
    $('#editParentMsg').append('<div>正在调整会员及本会员上级用户的下下级数量...</div>');
    $.ajax({
        url: '/admin/script/nextCount?type=next_next_count',
        type: 'get',
        async: true,
        success: function (res) {
            $('#editParentMsg').append('<div>调整会员及本会员上级用户的下下级数量完成</div>');
            $('#editParentMsg').append('<div>高管独立操作已完成可以关闭该弹窗了</div>');

        }
    })
}